<template>
  <div class="login">
  </div>
</template>

<script>
import {system,isRegister} from "request";
import { setWXConfig } from 'src/methods/baseinfo.js'
import {getOpenId} from "../methods/baseinfo.js";
import {loginConfig} from 'pack';
let portInfo = loginConfig();
export default {
  name: 'login',
  data () {
    return {
      msg: ''
    }
  },
  computed:{
  },
  created() {
    this.checkData();
  },
  mounted(){  
    setWXConfig(window.location.href.split('#')[0])
  },
  methods:{
    async checkData(){
        if(portInfo.packType){
            portInfo.userId = await getOpenId();
        }
        delete portInfo["packType"];
        // const openId = await getOpenId();
        // system({ "appId":"APP2018062500018","userId":openId,"institutionNo":"IN20180625000053",}).then(
        //system({ "appId":"APP2018062500018","userId":"oHp37w2pgB8dJDR0tt8HmBpqq4PE","institutionNo":"IN20180625000053",}).then( // 林丹账号测试
        system(portInfo).then(
                response => {
                    var obj = Object.assign({}, response.data)
                    if(response.rspCode=="0000"){
                        localStorage.setItem("token",obj.sessionId)
                        sessionStorage.setItem("colour",obj.colour)
                        sessionStorage.setItem("logourl",obj.logoPicUrl)
                        sessionStorage.setItem("institutionName",obj.institutionName)
                        sessionStorage.setItem('isHkb',"2");
                        this.judgeRegister();                           //判断是否注册手机号
                        let pageUrl = this.$route.query.pageUrl || '';  //如果有自定义跳转路由就跳到目标页面，没有就跳到首页
                        this.$router.push({ path:"/" + pageUrl})
                    }else if(response.rspCode=="4444"){
                        this.$router.push({
                            path:"/Notfound",
                            query:{
                                msg: "权限不足"
                            }
                        })
                    }else{
                        this.$router.push({
                            path:"/Notfound",
                            query: {msg: response.rspMsg}
                        })
                    }
                }).catch(   error => console.log(error) );
     
    },
    //判断用户是否绑定了手机号
    async judgeRegister(){
        await isRegister({}).then(res=>{
            if (res.data.result == "7012") {
                this.$store.commit("changeRegState",false);
            }else{
                this.$store.commit("changeRegState",true);
            }
            // console.log(this.$store.state.b.isRegisterPhone)
        }).catch(err=>console.log(err))
    }
  },  
  components: {
  }
}
</script>

<style scoped>

</style>
